package com.jd.orm.framework.core.transaction;

/**
 * 
 * ClassName: ResourceAccess <br/>
 * Function: RESOURCE ACCESS <br/>
 * Reason: TODO ADD REASON. <br/>
 * date: 2014-5-13 上午9:05:56 <br/>
 * 
 * @author liubing1@jd.com
 * @version @param <E>
 * @since up JDK 1.5
 */
public final class ResourceAccess<E> {
	final TransactionStatus transaction;
	final IResourceManager<E> resourceManager;
	private final E resource;

	/**
	 * 
	 * Creates a new instance of ResourceAccess.
	 * 
	 * @param transaction
	 * @param resourceManager
	 * @param resource
	 */
	ResourceAccess(TransactionStatus transaction,
			IResourceManager<E> resourceManager, E resource) {
		this.transaction = transaction;
		this.resourceManager = resourceManager;
		this.resource = resource;
	}

	/**
	 * 
	 * commitTransaction: <br/>
	 * TODO.<br/>
	 * 
	 * @author liubing1@jd.com
	 * @since JDK 1.5
	 */
	void commitTransaction() {
		resourceManager.commitTransaction(resource);
	}

	/**
	 * 
	 * rollbackTransaction: <br/>
	 * TODO.<br/>
	 * 
	 * @author liubing1@jd.com
	 * @throws Exception
	 * @since JDK 1.5
	 */
	void rollbackTransaction() throws Exception {
		resourceManager.rollbackTransaction(resource);
	}

	/**
	 * 
	 * getResource: <br/>
	 * TODO.<br/>
	 * 
	 * @author liubing1@jd.com
	 * @return
	 * @since JDK 1.5
	 */
	public E getResource() {
		return resource;
	}
}